<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>沈俞佑202031061479</title>
    <link rel="stylesheet" href="../css/index.css">
</head>
<body>
    <div class="book">
        <div class="cover cover_front"> 
            <br>
            <h1>《帅哥的通讯录》</h1>
            <h2>沈俞佑</h2>    
            <h2>202031061479</h2>
        </div>
        <div class="cover cover_back">
            <img src="https://serio.gitee.io/medias/logo.png" alt="">
        </div>
        <div class="page1 page">
            <div class="text">欢迎</div>
            
            <input type="text" placeholder="用户名" name="username" class="input" id="username">
            <input type="password" placeholder="密码" name="password" class="input" id="password">
            
            <button class="login_btn" onclick="login()">登录</button>
            <button class="register_btn" onclick="register()">注册</button>
        </div>
    </div>
    
</body>
<script src="../js/ajax.js"></script>
<script>
    const username = document.getElementById('username')
    const password = document.getElementById('password')
    function login() {    
        if((username.value).length < 2 || password.value.length < 3) {
            // alert('输入不合法,请检查用户名或密码')
            confirm('非法输入，请检查用户名或密码')
        } else {
           AJAX('POST', 'login', {'username':username.value, 'password':password.value}) 
        }
        
    }
    function register() {
        
        if((username.value).length < 2 || password.value.length < 3) {
            confirm('非法输入，请检查用户名或密码')
        } else {
            let luckynum = Math.random()*(19999999999 - 10000000000) + 10000000000
            AJAX('POST', 'register', {'username':username.value, 'password':password.value, 'phonenum':Number.parseInt(luckynum)})
        }
    }
</script>
</html>